<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改角色')" />
	<th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
	<form class="form-horizontal m" id="form-role-edit">
		<input type="hidden" name="productId" th:value="${poProduct.productId}">
		<div class="form-group">
			<label class="col-sm-3 control-label">品牌名称：</label>
			<div class="col-sm-8">
				<select name="brandId" class="form-control">
					<option value="">请选择</option>
					<option th:each="bl : ${brandList}" th:value="${bl.brandId}" th:selected="${bl.brandName} eq ${editPro.brandName}" th:text="${bl.brandName}"></option>
				</select>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">商品类型：</label>
			<div class="col-sm-8">
				<select name="poTypeId" class="form-control">
					<option value="">请选择</option>
					<option th:each="tl : ${proTypeList}" th:value="${tl.typeId}" th:selected="${tl.typeName} eq ${editPro.typeName}" th:text="${tl.typeName}"></option>
				</select>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">商品型号：</label>
			<div class="col-sm-8">
				<div class="input-group date">
					<input type="text" name="productModel" class="form-control" th:value="${poProduct.productModel}"/>
					<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
				</div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">单位：</label>
			<div class="col-sm-8">
				<div class="input-group date">
					<input type="text" name="unit" class="form-control" th:value="${poProduct.unit}"/>
					<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
				</div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">状态：</label>
			<div class="col-sm-8">
				<select name="status" class="form-control">
					<option value="">请选择</option>
					<option value="1" th:selected="${poProduct.status} eq 1">可用</option>
					<option value="0" th:selected="${poProduct.status} eq 0">不可用</option>
				</select>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">创建人：</label>
			<div class="col-sm-8">
				<input name="createUsername" class="form-control" type="text" th:value="${cUser.userName}" readonly>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">创建时间：</label>
			<div class="col-sm-8">
				<div class="input-group date">
					<input name="createTime" class="form-control" placeholder="yyyy-MM-dd" type="text" th:value="${poProduct.createTime}">
					<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
				</div>
			</div>
		</div>
	</form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: ztree-js" />
<script type="text/javascript">
	$(function() {
		var url = ctx + "product/manage/doEdit";
		var options = {
			id: "menuTrees",
			url: url,
			check: { enable: true },
			expandLevel: 0
		};
		$.tree.init(options);
	});

	$("#form-role-edit").validate({
		onkeyup: false,
		rules:{
			roleName:{
				remote: {
					url: ctx + "product/manage/doEdit",
					type: "post",
					dataType: "json",
					data: {
						"purId": function() {
							return $("#purId").val();
						}
					},
					dataFilter: function(data, type) {
						return $.validate.unique(data);
					}
				}
			},
			roleKey:{
				remote: {
					url: ctx + "product/manage/doEdit",
					type: "post",
					dataType: "json",
					data: {
						"purId": function() {
							return $("#purId").val();
						}
					},
					dataFilter: function(data, type) {
						return $.validate.unique(data);
					}
				}
			},
			roleSort:{
				digits:true
			},
		},
		messages: {
			"roleName": {
				remote: "角色名称已经存在"
			},
			"roleKey": {
				remote: "角色权限已经存在"
			}
		},
		focusCleanup: true
	});

	$('input').on('ifChanged', function(obj){
		var type = $(this).val();
		var checked = obj.currentTarget.checked;
		if (type == 1) {
			if (checked) {
				$._tree.expandAll(true);
			} else {
				$._tree.expandAll(false);
			}
		} else if (type == "2") {
			if (checked) {
				$._tree.checkAllNodes(true);
			} else {
				$._tree.checkAllNodes(false);
			}
		} else if (type == "3") {
			if (checked) {
				$._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
			} else {
				$._tree.setting.check.chkboxType = { "Y": "", "N": "" };
			}
		}
	})

	function edit() {

		var productId = $("input[name='productId']").val();
		var brandId = $("select[name='brandId']").val();
		var poTypeId = $("select[name='poTypeId']").val();
		var productModel = $("input[name='productModel']").val();
		var unit = $("input[name='unit']").val();
		var status = $("select[name='status']").val();
		var createUsername = $("input[name='createUsername']").val();
		var createTime = $("input[name='createTime']").val();
		var menuIds = $.tree.getCheckedNodes();
		$.ajax({
			cache : true,
			type : "POST",
			url : ctx + "product/manage/doEdit",
			data : {
				"productId": productId,
				"brandId": brandId,
				"poTypeId": poTypeId,
				"productModel": productModel,
				"unit": unit,
				"status": status,
				"createUsername": createUsername,
				"createTime": createTime,
				"menuIds": menuIds
			},
			async : false,
			error : function(request) {
				$.modal.alertError("系统错误");
			},
			success : function(data) {
				$.operate.successCallback(data);
			}
		});
	}

	function submitHandler() {
		if ($.validate.form()) {
			edit();
		}
	}
</script>
</body>
</html>
